package com.topvision.service.api.impl.glass;

import com.topvision.mapper.glass.SysFileUploadStatusMapper;
import com.topvision.mapper.glass.SysuploadMapper;
import com.topvision.model.glass.SysFileUploadStatus;
import com.topvision.model.glass.Sysupload;
import com.topvision.service.api.glass.AppLauncherService;
import com.topvision.service.api.glass.AppSysVersionService;
import com.topvision.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("appLauncherService")
public class AppLauncherServiceImpl implements AppLauncherService {

    @Autowired
    SysuploadMapper sysuploadMapper;
    @Autowired
    SysFileUploadStatusMapper sysFileUploadStatusMapper;

    @Override
    public SysFileUploadStatus get(String guid, String fileName) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("guid", guid);
        queryMap.put("filename", fileName);
        return sysFileUploadStatusMapper.queryObjectByMap(queryMap);
    }

    @Override
    public void updateChunk(SysFileUploadStatus sysFileUploadStatus) {
        sysFileUploadStatusMapper.update(sysFileUploadStatus);
    }

    @Override
    public void add(SysFileUploadStatus sysFileUploadStatus) {
        sysFileUploadStatusMapper.save(sysFileUploadStatus);
    }


    private String getFileName(String url) {
        if (StringUtils.isEmpty(url)) {
            return null;
        }
        int index = url.lastIndexOf("/");
        return url.substring(index + 1, url.length());

    }
}
